<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	StringBuffer strURL = request.getRequestURL();
	String URL = strURL.toString();
	String contPath = request.getContextPath();
	int nIndex = URL.indexOf(contPath);
	URL = "http://tugo.cn/weixin_aef/";
	%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="<%=URL%>newedition/css/aui.css" />
<link rel="stylesheet" href="<%=URL%>newedition/css/iconfont.css" />
<link rel="stylesheet" href="<%=URL%>newedition/css/aui-slide.css" />
<link rel="stylesheet"
	href="<%=URL%>newedition/css/aui-pull-refresh.css" />
<script type="text/javascript"
	src="<%=URL%>newedition/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/aui-slide.js"></script>
<script type="text/javascript" src="<%=URL%>js/base64.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/aui-toast.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/auipopupstyle.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/base.js?version=3.4"></script>
<script type="text/javascript"
	src="<%=URL%>js/cookies.js?version=1.1"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/aui-pull-refresh.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/doRefresh.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/aui-dialog.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/recycle/user_functionAddAddress.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/addressdemo.js"></script>
<title>发起售油</title>
</head>

<body>
	<header class="aui-bar aui-bar-nav "><!--  <a
		class="aui-pull-left aui-btn"> <span
		class="aui-iconfont aui-icon-left"></span>
	</a> -->
	<div class="aui-title">修改地址</div>
	<a class="aui-pull-right aui-btn " onclick="updateHistoryAddress()"> <span
		class="aui-iconfont ">保存</span>
	</a> </header>
	<div class="aui-refresh-content aui-margin-b-15">
		<ul class="aui-list aui-form-list">
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">联系电话</div>
					<div class="aui-list-item-input">
						<input type="tel" id="mobile" placeholder="请输入联系电话">
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">所属城市</div>
					<div class="aui-list-item-input aui-list-item-arrow">
						<select id="province">
						</select>
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">所属区域</div>
					<div class="aui-list-item-input aui-list-item-arrow">
						<select id="area">
						</select>
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">所属街道</div>
					<div class="aui-list-item-input aui-list-item-arrow">
						<select id="town">
						</select>
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-input">
						<textarea placeholder="请输入详细地址" id="baiduaddress"></textarea>
					</div>
				</div>
			</li>
		</ul>
		<div class="aui-padded-15"
			style="text-align: center; color: #8f8f8f; font-size: 0.6rem;">
			<input class="aui-checkbox aui-margin-r-5" type="checkbox"
				name="checkbox" id="defaultaddress" checked="" style="width: 0.8rem; height: 0.8rem;">设为默认地址
				
		</div>
	</div>
</body>
<script>
<%String addressid = (String) request.getParameter("addressid");%>
		var toast = new auiToast();

		$(function() {
			addressdemo("重庆市","province")
			getHistoryAddress()
		})
		function getHistoryAddress(){
				showDefault("loading","加载中...");
				var jsonstr = "filterscount=0&groupscount=0&pagenum=0&pagesize=10&recordstartindex=0&recordendindex=10&iphone="+getCookie("useriphone")+"&id="+<%=addressid%>+"";
				$.ajax({
					cache: false,
					type: "post",
					datatype: 'json',
					contentType: 'application/json;charset=UTF-8',
					data: jsonstr,
					url: ''+httpipstr+'alfa-mobile-ws/rest/historyaddress/findlist?mobiletoken='+getCookie("mobiletokenuser")+'',
					success: function(data) {
						toast.hide();
					 	$("#province option[text="+data.rows[0].province+"] ").val(data.rows[0].province );
					 	$("#area option[text="+data.rows[0].area+"] ").val(data.rows[0].area );
					 	$("#town option[text="+data.rows[0].townandstreets+"] ").val(data.rows[0].townandstreets );
					 	$("#mobile").val(data.rows[0].mobile );
					 	$("#baiduaddress").val(data.rows[0].fulladdress);
					}
				})
			}
		function updateHistoryAddress(){
			showDefault("loading","加载中...");
			var mobile=$("#mobile").val();
			 var province=$("#province").find("option:checked").html();
			 var area=$("#area").find("option:checked").html();
			 var town=$("#town").find("option:checked").html();
			 var address=$("#baiduaddress").val();
			 var id=<%=addressid%>
			var jsonstr1={"id":""+id+"","iphone":""+getCookie("useriphone")+"","address":""+province+area+town+address+"","mobile":""+mobile+"","townandstreets":""+town+"","province":""+province+"","city":""+province+"","area":""+area+"","fulladdress":""+address+""};
		<%-- 	var jsonstr = "filterscount=0&groupscount=0&pagenum=0&pagesize=10&recordstartindex=0&recordendindex=10&iphone="+getCookie("useriphone")+"&id="+<%=addressid%>+""; --%>
			$.ajax({
				cache: false,
				type: "post",
				datatype: 'json',
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(jsonstr1),
				url: ''+httpipstr+'alfa-mobile-ws/rest/historyaddress/updateHistoryAddress?mobiletoken='+getCookie("mobiletokenuser")+'',
				success: function(data) {
					toast.hide();
					if($("#defaultaddress").prop("checked")){
						var jsonstr = "filterscount=0&groupscount=0&pagenum=0&pagesize=10&recordstartindex=0&recordendindex=10&iphone="+getCookie("useriphone")+"&id="+<%=addressid%>+"";
						$.ajax({
							cache: false,
							type: "post",
							datatype: 'json',
							contentType: 'application/json;charset=UTF-8',
							data: jsonstr,
							url: ''+httpipstr+'alfa-mobile-ws/rest/historyaddress/findlist?mobiletoken='+getCookie("mobiletokenuser")+'',
							success: function(data) {
								setcookie("recycleaddress", data.rows[0].address, 30, "/");
								setcookie("recycleaddressid", data.rows[0].id, 30, "/");
								setcookie("recycleaddressiphone", data.rows[0].mobile, 30, "/");
								location.href="user_functionAddressList.jsp"
							}
						})
					}else{
						location.href="user_functionAddressList.jsp"
					}
				}
			})
		}
		dorefresh();
	</script>

</html>